package com.tbsoft.ehr.action.mydata;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionContext;
import com.tbsoft.ehr.action.BaseAction;
import com.tbsoft.ehr.login.LoginInfo;
import com.tbsoft.ehr.model.ContractVo;
import com.tbsoft.ehr.model.ProjectExperience;
import com.tbsoft.ehr.model.Resume;
import com.tbsoft.ehr.model.StaffInfo;
import com.tbsoft.ehr.service.contract.ContractService;
import com.tbsoft.ehr.service.resume.ResumeService;
import com.tbsoft.ehr.service.staffile.StaffFileService;

public class MyDataAction extends BaseAction {

	private StaffInfo staff;
	private Resume resume;
	private ContractVo contractVo;
	private List<ProjectExperience> projectExperienceList = new ArrayList<ProjectExperience>();
	
	private StaffFileService staffFileService;
	private ResumeService resumeService;
	private ContractService contractService;
	
	public StaffInfo getStaff() {
		return staff;
	}

	public void setStaff(StaffInfo staff) {
		this.staff = staff;
	}

	public Resume getResume() {
		return resume;
	}

	public void setResume(Resume resume) {
		this.resume = resume;
	}

	public ContractVo getContractVo() {
		return contractVo;
	}

	public void setContractVo(ContractVo contractVo) {
		this.contractVo = contractVo;
	}

	public List<ProjectExperience> getProjectExperienceList() {
		return projectExperienceList;
	}

	public void setProjectExperienceList(
			List<ProjectExperience> projectExperienceList) {
		this.projectExperienceList = projectExperienceList;
	}

	public void setStaffFileService(StaffFileService staffFileService) {
		this.staffFileService = staffFileService;
	}

	public void setResumeService(ResumeService resumeService) {
		this.resumeService = resumeService;
	}

	public void setContractService(ContractService contractService) {
		this.contractService = contractService;
	}

	public String queryStaffFile(){
		LoginInfo loginInfo = (LoginInfo)ActionContext.getContext().getSession().get("loginInfo");
		if(loginInfo!=null) {
			this.staff = this.staffFileService.getStaffFileByUserId(loginInfo.getUserId());
			if(this.staff!=null&&this.staff.getContracts().size()>0) {
				this.contractVo = this.contractService.genContractInfo(this.staff.getContracts());
			}
			return "browseStaffFile";
		} else {
			return errorReturn("没有查询到相关用户信息");
		}
	}
	
	public String queryResume(){
		LoginInfo loginInfo = (LoginInfo)ActionContext.getContext().getSession().get("loginInfo");
		if (loginInfo != null) {
			resume = this.resumeService
					.getResumeByUserId(loginInfo.getUserId());
			if (resume != null) {
				// 显示的时候对换行符进行处理
				resume.setOccupationalCharacteristics(resume
						.getOccupationalCharacteristics().replaceAll("\n",
								"<br/>"));
				resume.setSelfEvaluation(resume.getSelfEvaluation().replaceAll(
						"\n", "<br/>"));
				resume.setTechnicalExpertise(resume.getTechnicalExpertise()
						.replaceAll("\n", "<br/>"));
				projectExperienceList = resume.getProjectExperienceList();
				for (ProjectExperience pe : projectExperienceList) {
					pe
							.setJobDuties(pe.getJobDuties().replaceAll("\n",
									"<br/>"));
					pe.setMainTechnical(pe.getMainTechnical().replaceAll("\n",
							"<br/>"));
					pe.setProjectSummary(pe.getProjectSummary().replaceAll(
							"\n", "<br/>"));
				}
			}
			return "browseResume";
		} else {
			return errorReturn("没有查询到相关用户信息");
		}
	}
}
